import { createSlice } from "@reduxjs/toolkit";
import { Local } from "@/utils/local";
import { AppDispatch } from "@/store"
import { userfood } from "@/apis/foods"
const FoodStore = createSlice({
    name: "Foodstore",
    initialState: {
        catalog: [],
        createList: [],
    },
    reducers: {
        setCatalog: (state, { payload }) => {
            state.catalog = payload
        },
        setCreateList: (state, { payload }) => {
            state.createList = payload;
            console.log(payload, '拿到了')
        },

    }
})


export const { setCatalog, setCreateList, } = FoodStore.actions

const axios_create_list = () => {
    // userfood
    const user_Id = Local.get_info()._id

    return async (dispatch: AppDispatch) => {
        const result = await userfood(user_Id)
        console.log("first", result)
        dispatch(setCreateList(result.data))
    }
}
export { axios_create_list }
export default FoodStore.reducer;